From 87c0239ae1655bb92e08f75d1edc0f9fe27e0437 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Wed, 1 Feb 2017 00:02:42 +0100 Subject: [PATCH] babl: generate db in temporary file Fixing some of - but not all race conditions shown by concurrency stress test. --- babl/babl-cache.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/babl/babl-cache.c b/babl/babl-cache.c index 723ee50..5f7b716 100644 --- a/babl/babl-cache.c +++ b/babl/babl-cache.c @@ -162,7 +162,11 @@ void babl_store_db (void) { BablDb *db = babl_fish_db (); int i; - FILE *dbfile = fopen (fish_cache_path (), "w"); + char *tmpp = calloc(8000,1); + FILE *dbfile; + + sprintf (tmpp, "%s~", fish_cache_path ()); + dbfile = fopen (tmpp, "w"); if (!dbfile) return; fprintf (dbfile, "%s\n", cache_header ()); @@ -181,6 +185,9 @@ void babl_store_db (void) fprintf (dbfile, "%s----\n", tmp); } fclose (dbfile); + + rename (tmpp, fish_cache_path()); + free (tmpp); } static int -- 2.30.2